﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.Services;
using System.Data.SqlClient;
using DB;

/// <summary>
///SceneryService 的摘要说明
/// </summary>
[WebService(Namespace = "http://lab365.org/")]
[WebServiceBinding(ConformsTo = WsiProfiles.BasicProfile1_1)]
//若要允许使用 ASP.NET AJAX 从脚本中调用此 Web 服务，请取消对下行的注释。 
// [System.Web.Script.Services.ScriptService]
public class SceneryService : System.Web.Services.WebService {

    public SceneryService () {

        //如果使用设计的组件，请取消注释以下行 
        //InitializeComponent(); 
    }

    [WebMethod]
    public List<Scenery> ListSceneriesByCity(string cityName)
    {
        List<Scenery> sceneryList = new List<Scenery>();
        DataAccess da = new DataAccess();
        SqlDataReader dr = da.GetDataReader(
            "SELECT [sceneryID],[sceneryName],[province],[city],[level],isnull([imageURL],'') as [imageURL],isnull([description],'') as [description],isnull([price],'') as [price],isnull([creditCardNum],'') as [creditCardNum] FROM [Sceneries] where city='" 
            + cityName + "'");
        while (dr.Read())
        {
            sceneryList.Add(new Scenery(dr.GetValue(0).ToString(), dr.GetValue(1).ToString(), dr.GetValue(2).ToString(),
                dr.GetValue(3).ToString(), dr.GetValue(4).ToString(), dr.GetValue(5).ToString(), dr.GetValue(6).ToString(), dr.GetValue(7).ToString(), dr.GetValue(8).ToString()));
        }
        return sceneryList.Count > 0 ? sceneryList : null;
    }

    [WebMethod]
    public List<Scenery> ListSceneriesByName(string sceneryName)
    {
        List<Scenery> sceneryList = new List<Scenery>();
        DataAccess da = new DataAccess();
        SqlDataReader dr = da.GetDataReader(
            "SELECT [sceneryID],[sceneryName],[province],[city],[level],isnull([imageURL],'') as [imageURL],isnull([description],'') as [description],isnull([price],'') as [price],isnull([creditCardNum],'') as [creditCardNum] FROM [Sceneries] where sceneryName='"
            + sceneryName + "'");
        while (dr.Read())
        {
            sceneryList.Add(new Scenery(dr.GetValue(0).ToString(), dr.GetValue(1).ToString(), dr.GetValue(2).ToString(),
                dr.GetValue(3).ToString(), dr.GetValue(4).ToString(), dr.GetValue(5).ToString(), dr.GetValue(6).ToString(), dr.GetValue(7).ToString(), dr.GetValue(8).ToString()));
        }
        return sceneryList.Count > 0 ? sceneryList : null;
    }

    [WebMethod]
    public Scenery GetSceneryByID(string sceneryID)
    {
        Scenery scenery;
        DataAccess da = new DataAccess();
        SqlDataReader dr = da.GetDataReader(
            "SELECT [sceneryID],[sceneryName],[province],[city],[level],isnull([imageURL],'') as [imageURL],isnull([description],'') as [description],isnull([price],'') as [price],isnull([creditCardNum],'') as [creditCardNum] FROM [Sceneries] where sceneryID='"
            + sceneryID + "'");
        if(dr.Read())
        {
            scenery = new Scenery(dr.GetValue(0).ToString(), dr.GetValue(1).ToString(), dr.GetValue(2).ToString(),
                dr.GetValue(3).ToString(), dr.GetValue(4).ToString(), dr.GetValue(5).ToString(), dr.GetValue(6).ToString(), dr.GetValue(7).ToString(), dr.GetValue(8).ToString());
            return scenery;
        }
        return null;
    }
}

